classdef PowerSupply < Instrument
    %POWERSUPPLY Summary of this class goes here
    %   Detailed explanation goes here
        
    properties
        voltage
        current_limit
        output_state
    end
    
    methods(Static)
        function test()
            DC = PowerSupply(0,5);
            try
                DC.set_voltage(12);
                DC.set_current_limit(0.42);
                DC.set_output_state('on');
                disp(DC.measure());
                DC.set_output_state('off');
            catch error
                disp(error)
            end
            DC.delete();
        end
    end
    
    methods
        function this = PowerSupply(GPIB_controller, GPIB_address, address)
            this = this@Instrument(GPIB_controller, GPIB_address, address);
        end
        
        function delete(this)
            this.set_output_state('off');
            this.set_voltage(0);
            delete@Instrument(this);
            disp('delete DC');
        end
        
        function set_voltage(this, voltage)
            this.voltage = voltage;
            str = sprintf('VOLT %f',this.voltage);
            fprintf(this.conn,str);
        end
        
        function set_current_limit(this, current_limit)
            this.current_limit = current_limit;
            str = sprintf('CURR %f',this.current_limit);
            fprintf(this.conn,str);
        end
        
        function set_output_state(this, output_state)
            this.output_state = output_state;
            fprintf(this.conn, ['OUTP ' output_state]);
        end
        
        function result = measure(this)
            fprintf(this.conn,'MEAS:CURR?');
            result = str2double(fscanf(this.conn));
        end
    end
    
end

